<?php
/**
 * All helper functions.
 */
class Helper 
{
	public function setPassword()
	{
		$length = 5;
		$chars = array_merge(range(0,9), range('a','z'));
		shuffle($chars);
		$password = implode(array_slice($chars, 0, $length));
		return $password;
	}
	
	public function fomatNumber($num)
	{
		return sprintf("%03d",$num);
		
	}
	
	public static  function  getImageSize ($file)
	{
		return getimagesize($file);
	}
	
	public static function uploadfile ($model,$attr)
	{
	if ($ufile=CUploadedFile::getInstance($model,$attr)) {
	  $newfname = time().Helper::setPassword().'.'.$ufile->getExtensionName();
	  $ufile->saveAs(dirname(Yii::app()->request->scriptFile) . '/assets/uploads/documents/' . $newfname);
	  return $newfname;
	}
	return false;
	}
	
	public static function encrypting($string="") {
		$hash = "md5";
		if ($hash=="md5")
		return md5($string);
		if ($hash=="sha1")
		return sha1($string);
		else
		return hash($hash,$string);
	}
	
	public static function sendMail($email,$subject,$message) {
		//echo $message;Yii::app()->end();
		$adminEmail = Yii::app()->params['adminEmail'];
		$headers = "MIME-Version: 1.0\r\nFrom: $adminEmail\r\nReply-To: $adminEmail\r\nContent-Type: text/html; charset=utf-8";
		$message = wordwrap($message, 70);
		$message = str_replace("\n.", "\n..", $message);
		return mail($email,'=?UTF-8?B?'.base64_encode($subject).'?=',$message,$headers);
	}
	
}